<?php
$txtTenchiendich=replatestring($_POST[txtTenchiendich],false);
$txtMachiendich=replatestring($_POST[txtMachiendich],false);
$txtNgaybatdau=replatestring($_POST[txtNgaybatdau],false);
$txtKetthuc=replatestring($_POST[txtKetthuc],false);

$txtNgansach=replatestring($_POST[txtNgansach],false);
$txtMuctieu=replatestring($_POST[txtMuctieu],false);
$txtKyvong=replatestring($_POST[txtKyvong],false);
$txtDoanhthu=replatestring($_POST[txtDoanhthu],false);

$IDLoaiCD=$_POST['IDLoaiCD'];
$txtTrangthai=$_POST['txtTrangthai'];

$sanphamsudung=$_POST['sanphamsudung'];
$txtSanpham=$_POST['sanphamsudung_id'];
if($txtSanpham==""){$txtSanpham=$sanphamsudung;}

$donviquanly=$_POST['donviquanly'];
$txtNguoiquanly=$_POST['txtNguoiquanly'];

$txtNguoitao=$_POST['txtNguoitao'];
$txtNgaytao=$_POST['txtNgaytao'];
$txtNguoicapnhat=$_POST['txtNguoicapnhat'];
$txtNgaycapnhat=$_POST['txtNgaycapnhat'];
$txtnoidung=$_POST['txtnoidung'];


$id=$_POST['id'];
$soanh=$_POST['hdnsoanh'];
$hinhanhsp ="";
for($i=1;$i<=$soanh;$i++){
	if($i<$soanh)$hinhanhsp .= $_POST["sanpham_hinhanh".$i]."~";
	else $hinhanhsp .= $_POST["sanpham_hinhanh".$i];
}
$date=time();

$Nguoi_Quan_Ly_Khac=$_POST['Nguoi_Quan_Ly_Khac'];

	if($id==""){		
		mysql_query("insert into tb_marketing
(Maso,Tenchiendich,marketing_ngansach,marketing_KHmuctieu,marketing_KHKyvong,	marketing_batdau,marketing_ketthuc,marketing_Mota,marketing_file,marketing_ngaytao,marketing_Ngayupdate,marketing_trangthai,IDSanpham,IDmanager_other,marketing_userupdate,marketing_DTKyvong,IDloai,account_id,room_id,marketing_Nguoitao)
		value('$txtMachiendich','$txtTenchiendich','$txtNgansach','$txtMuctieu','$txtKyvong','$txtNgaybatdau','$txtKetthuc','$txtnoidung','$hinhanhsp','$date','$date','$txtTrangthai','$txtSanpham','$Nguoi_Quan_Ly_Khac','$txtNguoicapnhat','$txtDoanhthu','$IDLoaiCD','$txtNguoiquanly','$donviquanly','$txtNguoitao')");
	
		$khachhang_id=mysql_insert_id();			
		$cauthongbao="Thêm thành công";
		$link=$url_main_site."system/index.php?tn=marketing";
		thongbao($cauthongbao,$link);
	}
	else
	{		
	
	
			
			mysql_query("
					update tb_marketing set 
						Maso='$txtMachiendich',
						Tenchiendich='$txtTenchiendich',
						marketing_ngansach='$txtNgansach',
						marketing_KHmuctieu='$txtMuctieu',
						marketing_KHKyvong='$txtKyvong',
						marketing_batdau='$txtNgaybatdau',
						marketing_ketthuc='$txtKetthuc',
						marketing_Mota='$txtnoidung',
						marketing_file='$hinhanhsp',						
						marketing_Ngayupdate='$date',
						marketing_trangthai='$txtTrangthai',
						IDSanpham='$txtSanpham',
						room_id='$donviquanly',
						IDmanager_other='$Nguoi_Quan_Ly_Khac',
						marketing_userupdate='$txtNguoicapnhat',
						marketing_DTKyvong='$txtDoanhthu',
						IDloai='$IDLoaiCD',
						account_id='$txtNguoiquanly'					
					where IDmarketing='$id'
			");
			
			$cauthongbao="Bạn đã sửa thành công";
			$link=$url_main_site."system/index.php?tn=marketing";
			thongbao($cauthongbao,$link);	
		
		
	}
					
?>